package com.newasia.server.common.strategy.dataConversion;

import com.newasia.server.dal.entitys.BaseData;

import java.lang.reflect.Method;
import java.util.List;

/**
 * @author LiChong
 * @description 历史详情数据
 * @date 2020/5/25
 */

public class HistoryData implements DataInvoke {

    @Override
    public Object invoke(Object proxyObj, Method method, Object[] args) throws Throwable{
        Object object = method.invoke(proxyObj,args);
        Class returnType = method.getReturnType();
        if (returnType.isAssignableFrom(List.class)) {
            List monitors = (List) object;
            for (Object monitor : monitors) {
                monitor.getClass().getMethod("setTemplate").invoke(monitor);
            }
            return monitors;
        } else if (returnType.isAssignableFrom(BaseData.class)) {
            object.getClass().getMethod("setTemplate").invoke(object);
            return object;
        }
        return object;
    }
}
